package com.tianma.upload.uploadjartest.socket.udp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;

/**
 * @author lgc
 * @createDate 2020/8/17 - 14:48
 */
public class DatagramSocketTest {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        DatagramSocket datagramSocket = new DatagramSocket();
        while (true){
            String s = br.readLine();

            byte[] bytes = s.getBytes();
            DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 8888);
            datagramSocket.send(datagramPacket);
            if (s.equals("bye")){
                break;
            }
        }
        datagramSocket.close();
    }
}
